package org.hbgl.geoentity.admin.web.admin;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.hbgl.geoentity.admin.annotation.RequiresPermissionsDesc;
import org.hbgl.geoentity.admin.web.BaseController;
import org.hbgl.geoentity.core.util.ResponseUtil;
import org.hbgl.geoentity.core.validator.Order;
import org.hbgl.geoentity.core.validator.Sort;
import org.hbgl.geoentity.db.domain.LogExamine;
import org.hbgl.geoentity.db.domain.LogLogin;
import org.hbgl.geoentity.db.domain.LogOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 代码功能：系统日志
 * 开发日期：2022/4/27
 * 作者：蒋海仑
 * 联系方式：
 * 版本更迭说明：
 * 版权信息：河北广联信息技术有限公司
 */
@RestController
@RequestMapping("/admin/log")
@Validated
public class AdminLogController extends BaseController {

    /**
     * 审核日志列表
     *
     * @param keywords 模糊查询
     * @param page     页码
     * @param limit    分页大小
     * @param sort     排序字段
     * @param order    排序方式
     */
    @RequiresPermissions("admin:log:examine")
    @RequiresPermissionsDesc(menu = {"系统日志", "审核日志"}, button = "查询")
    @GetMapping("/examine/list")
    public Object examineList(@RequestParam(defaultValue = "-2") Integer examState,
                              @RequestParam(defaultValue = "") String keywords,
                                @RequestParam(defaultValue = "") String start,
                                @RequestParam(defaultValue = "") String end,
                                @RequestParam(defaultValue = "1") Integer page,
                                @RequestParam(defaultValue = "10") Integer limit,
                                @Sort @RequestParam(defaultValue = "operation_time") String sort,
                                @Order @RequestParam(defaultValue = "desc") String order) {
        List<LogExamine> examineList = logService.queryLogExamineSelective(examState, keywords, start, end, page, limit, sort, order);
        return ResponseUtil.okList(examineList);
    }

    /**
     * 操作日志列表
     *
     * @param keywords 模糊查询
     * @param page     页码
     * @param limit    分页大小
     * @param sort     排序字段
     * @param order    排序方式
     */
    @RequiresPermissions("admin:log:operation")
    @RequiresPermissionsDesc(menu = {"系统日志", "操作日志"}, button = "查询")
    @GetMapping("/operation/list")
    public Object operationList(@RequestParam(defaultValue = "") String keywords,
                                @RequestParam(defaultValue = "") String start,
                                @RequestParam(defaultValue = "") String end,
                                @RequestParam(defaultValue = "1") Integer page,
                                @RequestParam(defaultValue = "10") Integer limit,
                                @Sort @RequestParam(defaultValue = "operation_time") String sort,
                                @Order @RequestParam(defaultValue = "desc") String order) {
        List<LogOperation> operationList = logService.queryLogOperationSelective(keywords, start, end, page, limit, sort, order);
        return ResponseUtil.okList(operationList);
    }

    /**
     * 登录日志列表
     *
     * @param keywords 模糊查询
     * @param page     页码
     * @param limit    分页大小
     * @param sort     排序字段
     * @param order    排序方式
     */
    @RequiresPermissions("admin:log:login")
    @RequiresPermissionsDesc(menu = {"系统日志", "登录日志"}, button = "查询")
    @GetMapping("/login/list")
    public Object loginList(@RequestParam(defaultValue = "") String keywords,
                            @RequestParam(defaultValue = "") String start,
                            @RequestParam(defaultValue = "") String end,
                            @RequestParam(defaultValue = "1") Integer page,
                            @RequestParam(defaultValue = "10") Integer limit,
                            @Sort @RequestParam(defaultValue = "login_time") String sort,
                            @Order @RequestParam(defaultValue = "desc") String order) {
        List<LogLogin> loginList = logService.queryLogLoginSelective(keywords, start, end, page, limit, sort, order);
        return ResponseUtil.okList(loginList);
    }

}
